package com.itlong.cloud.miniprogram.resource;

import com.itlong.cloud.POJO.VO.app.AppUserCacheVO;
import com.itlong.cloud.miniprogram.service.IMiniProgramLoginService;
import com.itlong.cloud.user.miniprogram.IMiniProgramLoginServiceClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <desc>
 *     微信小程序的登录版块接口代理实现
 * </desc>
 *
 * @createDate 2018/11/24.
 */
@RestController
public class MiniProgramLoginServiceResource implements IMiniProgramLoginServiceClient {
    @Autowired
    IMiniProgramLoginService iMiniProgramLoginService;


    /**
     * <desc>
     *      根据手机号进行注册或登录
     * </desc>
     * @param phoneNo  手机号
     * @return
     * @author Juguang.S
     * @createDate 2018/11/24
     */
    @Override
    @RequestMapping(path = "/miniProgram/user/login",method = RequestMethod.POST)
    public AppUserCacheVO login(@RequestParam("phoneNo") String phoneNo,
                                @RequestParam("openId") String openId,
                                @RequestParam(value = "unionId",required = false) String unionId) throws Exception {
        return iMiniProgramLoginService.login(phoneNo,openId,unionId);
    }

    /**
     * <desc>
     *      校验该用户是否被禁用
     * </desc>
     *
     * @param phoneNo  手机号
     * @return
     * @author Juguang.S
     * @createDate 2019/01/05
     */
    @RequestMapping(path = "/miniProgram/user/getUserStatus",method = RequestMethod.POST)
    public Integer getUserStatus(@RequestParam("phoneNo") String phoneNo) throws Exception{
        return iMiniProgramLoginService.getUserStatus(phoneNo);
    }

    /**
     * <desc>
     *     退出登录
     * </desc>
     *
     * @param token
     * @return
     * @author Juguang.S
     * @createDate 2018/11/24
     */
    @Override
    @RequestMapping(path = "/miniProgram/user/loginOut",method = RequestMethod.POST)
    public void loginOut(@RequestParam("token") String token) throws Exception{
        iMiniProgramLoginService.loginOut(token);
    }

    /**
     * <desc>
     *      从缓存获取用户信息
     * </desc>
     *
     * @param token
     * @return
     * @author Juguang.S
     * @createDate 2018/11/26
     */
    @Override
    @RequestMapping(path = "/miniProgram/user/retrieve")
    public AppUserCacheVO retrieve(@RequestParam("token")String token){
        return iMiniProgramLoginService.retrieve(token);
    }

    /**
     * <desc>
     *     微信小程序登录后缓存用户信息
     * </desc>
     * @param appUserCacheVO
     * @return
     * @author Juguang.S
     * @createDate 2018/11/26
     */
    @Override
    @RequestMapping(path = "/miniProgram/user/loginCacheUserVO",method = RequestMethod.POST)
    public boolean loginCacheUserVO(@RequestBody AppUserCacheVO appUserCacheVO) throws Exception{
        return iMiniProgramLoginService.loginCacheUserVO(appUserCacheVO);
    }

    /**
     * <desc>
     *      从缓存获取用户信息 用于校验token是否过期
     * </desc>
     *
     * @param token
     * @return
     * @author Juguang.S
     * @createDate 2020/03/10
     */
    @Override
    @RequestMapping(path = "/miniProgram/user/retrieveByCheckToken")
    public AppUserCacheVO retrieveByCheckToken(@RequestParam("token")String token){
        return iMiniProgramLoginService.retrieveByCheckToken(token);
    }


}
